import axios from '@/untils/request'

// 获取所有频道到列表
export const allChannelsAPI = () => axios({ url: '/v1_0/channels' })

// 登录注册
export const userLoginAPI = ({ mobile, code }) => axios({ url: '/v1_0/authorizations', method: 'POST', data: { mobile, code } })

// 获取用户选择的频道
export const getUserChannelAPI = () => axios({ url: '/v1_0/user/channels' })

// 获取文章新闻推荐
export const getArticleNewsAPI = ({ channel_id, timestamp }) => axios({ url: '/v1_0/articles', params: { channel_id, timestamp } })

// 对文章进行不感兴趣反馈
export const dislikeArticleAPI = (target) => axios({ url: '/v1_0/article/dislikes', method: 'POST', data: { target } })

// 举报文章
export const reportArticleAPI = ({ target, type }) => axios({ url: '/v1_0/article/reports', method: 'POST', data: { target, type, remark: '************' } })

// 获取文章详情
export const getArticleDetailAPI = (article_id) => axios({ url: `/v1_0/articles/${article_id}` })

// 更新已选频道
export const updateChannelAPI = (channels) => axios({ url: '/v1_0/user/channels', method: 'PUT', data: { channels } })

// 自动补全
export const autoCompletionAPI = (q) => axios({ url: '/v1_0/suggestion', params: { q } })

// 获取搜索结果
export const getSearchResultAPI = ({ q, page, per_page }) => axios({ url: '/v1_0/search', params: { q, page, per_page } })

// 关注用户
export const attentionUserAPI = ({ target }) => axios({ url: '/v1_0/user/followings', method: 'POST', data: { target } })

// 取消关注
export const cancelAttentionUserAPI = ({ target }) => axios({ url: `/v1_0/user/followings/${target}`, method: 'DELETE' })

// 点赞
export const giveALikeAPI = ({ target }) => axios({ url: '/v1_0/article/likings', method: 'POST', data: { target } })

// 取消点赞
export const cancelGiveALikeAPI = ({ target }) => axios({ url: `/v1_0/article/likings/${target}`, method: 'DELETE' })

// 收藏文章
export const collectArticleAPI = ({ target }) => axios({ url: '/v1_0/article/collections', method: 'POST', data: { target } })

// 取消收藏
export const cancelCollectArticleAPI = ({ target }) => axios({ url: `/v1_0/article/collections/${target}`, method: 'DELETE' })

// 获取文章评论
export const getArticleCommentAPI = ({ type, source }) => axios({ url: '/v1_0/comments', params: { type, source } })

// 对评论点赞
export const giveALikeToCommentAPI = ({ target }) => axios({ url: '/v1_0/comment/likings', method: 'POST', data: { target } })

// 取消对评论点赞
export const cancelGiveALikeToCommentAPI = ({ target }) => axios({ url: `/v1_0/comment/likings/${target}`, method: 'DELETE' })

// 发表评论
export const publishedCommentAPI = ({ target, content }) => axios({ url: '/v1_0/comments', method: 'POST', data: { target, content } })

// 获取用户个人信息
export const getUserInfoAPI = () => axios({ url: '/v1_0/user' })

// 获取用户个人资料
export const getUserDataAPI = () => axios({ url: '/v1_0/user/profile' })

// 编辑照片
export const editUserPhotoAPI = ({ photo }) => axios({ url: '/v1_0/user/photo', method: 'PATCH', data: { photo }, headers: { 'Content-Type': 'multipart/form-data' } })

// 编辑用户信息
export const editUserInfoAPI = ({ name, gender, birthday }) => axios({ url: '/v1_0/user/profile', method: 'PATCH', data: { name, gender, birthday } })

// 小智同学
export const connectWebsocketAPI = ({ msg, timestamp }) => axios({ url: '/v1_0/socket.io/', method: 'POST', data: { msg, timestamp } })
